package com.aura.lyngen.core.parser;

import com.aura.lyngen.exception.BusinessException;
import com.aura.lyngen.exception.ErrorCode;
import com.aura.lyngen.model.enums.CodeGenTypeEnum;

import java.util.Map;

/**
 * @ClassName CodeParserExecutor
 * @Description 代码解析执行器
 * @Author ZJX
 * @Date 2025/9/1 15:56
 * @Version 1.0
 **/
public class CodeParserExecutor {

    /**
     * 代码解析策略 使用 Map 进行一一映射
     */
    private static final Map<CodeGenTypeEnum, CodeParserStrategy<?>> PARSER_MAP = Map.of(
            CodeGenTypeEnum.HTML, new HtmlCodeParser(),
            CodeGenTypeEnum.MULTI_FILE, new MultiFileCodeParser()
    );

    /**
     * 执行代码解析
     *
     * @param codeContent     代码内容
     * @param codeGenTypeEnum 代码生成类型
     * @return 解析结果
     */
    public static Object executeParser(String codeContent, CodeGenTypeEnum codeGenTypeEnum) {
        CodeParserStrategy<?> parserStrategy = PARSER_MAP.get(codeGenTypeEnum);
        if (parserStrategy == null) {
            throw new BusinessException(ErrorCode.AI_CODE_GEN_TYPE_INVALID, "不支持的代码生成类型");
        }
        return parserStrategy.parseCode(codeContent);
    }
}
